<?php


namespace app\home\controller;


use app\base\BaseController;
use think\facade\Db;
use think\facade\View;

/**
 * Class ProcessInventory
 * @package app\home\controller
 * 工序库存
 */
class ProcessInventory extends BaseController
{
    protected $table='out_material_view';
    protected $title='工序库存表';

    /**
     * @return \json|\think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * date:2024/4/28
     */
    public function index()
    {
        halt('开发中');
        $param=$this->param;
        if (request()->isAjax()) {

            $where[]=['status','=',1];
            foreach (['bar_code','mdName','specs'] as $i){
                if (isset($param[$i])&&$param[$i]){
                    $where[]=[$i,'like',"%".$param[$i].'%'];
                }
            }
            if (isset($param['type'])&&$param['type']){
                $where[]=['mdType','=',$param['type']];
            }
            foreach (['warehouse_id','locator'] as $i){
                if (isset($param[$i])&&$param[$i]){
                    $where[]=[$i,'in',$param[$i]];
                }
            }
            $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
            $list = Db::name($this->table)
                ->where($where)
                ->field("*")
                ->paginate($rows)->each(function ($item,$index){
                    $item['hasNum']=$item['num']-$item['sendedNum'];
                    return $item;
                });
            return table_assign(0, '', $list);
        } else {
            $warehouse=Db::name('warehouse')->where('status',1)->field('id,name')->select();
            View::assign('warehouseList',$warehouse);
            return view();
        }

    }
}